package edu.buffalo.cse.cse486_586.simpledht.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import android.util.Log;

public class SendingThread implements Runnable {
	// Debug params
	final private String TAG = "ListeningThread";
	// final private Boolean isDebug = true;

	private String ip;
	private int port;
	private String pkgStr;

	public SendingThread(String ip, int port, String str) {
		this.ip = ip;
		this.port = port;
		this.pkgStr = str;
	}

	@Override
	public void run() {
		Socket s;
		try {
			s = new Socket(this.ip, this.port);
			PrintWriter out = new PrintWriter(s.getOutputStream(), true);
			Log.d(TAG, "send to " + this.port + "===>" + this.pkgStr);
			out.print(this.pkgStr);
			out.close();
			s.close();
		} catch (UnknownHostException e) {
			Log.e(TAG, "Exception", e);
		} catch (IOException e) {
			Log.e(TAG, "Exception", e);
		}
	}

}
